<!--
 * @Author: xiuquanxu
 * @Company: kaochong
 * @Date: 2021-04-06 16:46:53
 * @LastEditors: xiuquanxu
 * @LastEditTime: 2021-04-08 19:02:25
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="addCanvas()">add</button>
    <div id="parent">

    </div>
</body>
<!-- <script src="./worker.js"></script> -->
<script type="module">
    import { text }  from './worker.js'
    console.log(text.toString());
    const worker = new window.Worker(window.URL.createObjectURL(new window.Blob([text.toString()])));
    worker.onmessage = (e) => {
        console.log(e.data);
    };
    setInterval(() => {
        worker.postMessage('parent message');
    }, 2 * 1000);
</script>
<script type="text/javascript" src="./xhr.js"></script>
<script>
    const p = document.getElementById('parent');
    let i = 0;
    function addCanvas() {
        i += 1;
        p.appendChild(createCanvas(i));
    }

    function createCanvas(id) {
        const c = document.createElement('canvas');
        c.id = id;
        c.width = 400;
        c.height = 400;
        return c;
    }
</script>
</html>